package com.zzyl.service.impl;

import com.github.pagehelper.Page;

import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;


import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description NursingProjectServiceImpl
 * @Author CWJ
 * @Date 2025-05-08  11:38
 */
@Service
public class NursingProjectServiceImpl implements NursingProjectService {

    @Autowired
    public NursingProjectMapper nursingProjectMapper;


    @Override
    public PageResponse<NursingProjectVo> getByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingProject> nursingProjects = nursingProjectMapper.selectByPage(name, status);
        PageResponse<NursingProjectVo> projectVoPageResponse = PageResponse.of(nursingProjects, NursingProjectVo.class);
        return projectVoPageResponse;
    }

    @Override
    public void add(NursingProject nursingProject) {
        // 检查是否存在相同名称的护理项目
        NursingProject existing = nursingProjectMapper.selectByName(nursingProject.getName());
        if (existing != null) {
            throw new RuntimeException("护理项目名称已存在: " + nursingProject.getName());
        }
        // 插入新的护理项目
        nursingProjectMapper.insert(nursingProject);
    }

    @Override
    public NursingProject getById(Integer id) {
        NursingProject nursingProject = nursingProjectMapper.selectByPrimaryKey(id);

        return nursingProject;
    }

    //编辑数据
    @Override
    public void edit(NursingProject nursingProject) {
        nursingProjectMapper.edit(nursingProject);
    }

    @Override
    public void eq(NursingProject nursingProject) {
        nursingProjectMapper.eqstatus(nursingProject);
    }

    @Override
    public void delete(Long id) {
        nursingProjectMapper.delete(id);
    }

    @Override
    public List<NursingProject> getAll() {
        return nursingProjectMapper.selectAll();
    }

}
